package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppSite;
import com.ruoyi.background.service.IAppSiteService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 知识关卡Controller
 *
 * @author susu
 * @date 2024-08-10
 */
@RestController
@RequestMapping("/applet/appSite")
public class AppSiteController extends BaseController {
    @Autowired
    private IAppSiteService appSiteService;

    /**
     * 查询知识关卡列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppSite appSite) {
        startPage();
        List<AppSite> list = appSiteService.selectAppSiteList(appSite);
        return getDataTable(list);
    }


    /**
     * 查询知识关卡列表下拉选择
     */
    @GetMapping("/select")
    public AjaxResult select() {
        List<AppSite> list = appSiteService.selectAppSiteSelect();
        return AjaxResult.success(list);
    }


    /**
     * 导出知识关卡列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:export')")
    @Log(title = "知识关卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppSite appSite) {
        List<AppSite> list = appSiteService.selectAppSiteList(appSite);
        ExcelUtil<AppSite> util = new ExcelUtil<AppSite>(AppSite.class);
        util.exportExcel(response, list, "知识关卡数据");
    }

    /**
     * 获取知识关卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appSiteService.selectAppSiteById(id));
    }

    /**
     * 新增知识关卡
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:add')")
    @Log(title = "知识关卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppSite appSite) {
        return toAjax(appSiteService.insertAppSite(appSite));
    }

    /**
     * 修改知识关卡
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:edit')")
    @Log(title = "知识关卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppSite appSite) {
        return toAjax(appSiteService.updateAppSite(appSite));
    }


    /**
     * 修改知识关卡状态
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:edit')")
    @Log(title = "知识关卡", businessType = BusinessType.UPDATE)
    @GetMapping("changeStatus/{id}/{status}")
    public AjaxResult editStatus(@PathVariable Long id, @PathVariable Integer status) {
        return toAjax(appSiteService.changeStatus(id, status));
    }

    /**
     * 删除知识关卡
     */
    @PreAuthorize("@ss.hasPermi('applet:appSite:remove')")
    @Log(title = "知识关卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appSiteService.deleteAppSiteByIds(ids));
    }
}
